DEMO: The playRandomNote Method

The playRandomNote method, which is contained inside Music Object Extension - Dynamic, offers a multitude parameters that can be used to change the resulting randomly selected musical note. You can randomize properties such as pitch, velocity, pan, duration, and volume.

Just a Link - One
Just a Link - Two
Just a Link - Three
Just a Link - Four
Just a Link - Five
Just a Link - Six
Just a Link - Seven
Just a Link - Eight

The table of links to the left demonstrates how you can use the playRandomNote method to achieve very cool effects. The ONMOUSEOVER event for each link triggers a randomly pitched musical note that plays through Beatnik's "Echo Bell" instrument. However, there is an added little subtlety: moving from top to bottom, the range within which a random pitch is selected descends, so that the top-most link always plays a random pitch within a very high range, and the bottom link always plays a random pitch within a very low range.

Pretend for a moment that the table of links is actually a navigation bar that is in a frame on the left hand side of a frames-based Web site. This "nav bar" would then be sonified in such an entertaining way that users would have fun just interacting with the nav bar itself. Just think if the entire Web site was interactive in a tasty and dynamic way. Try interacting with the links in the table. You can actually almost play them like a musical instrument if you "swirl" the mouse around, moving gradually from top to bottom, and at varying speed. Take the links for a test drive...

Now, let's take a look at the source code for this navigation bar...

<HTML><TITLE>Whacky Navigation Bar</TITLE></HTML>
<BODY>

<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-dynamic.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

music = new Music ();
music.stubEmbed ('stub.rmf');

// --></SCRIPT>

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=6 BGCOLOR=EEEEEE ALIGN=LEFT HSPACE=8><TR><TD>
   <FONT FACE="ARIAL,HELVETICA,VERDANA">
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (1,1,10,100,110,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;One
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (2,1,10,90,100,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Two
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (3,1,10,80,90,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Three
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (4,1,10,70,80,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Four
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (5,1,10,60,70,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Five
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (6,1,10,50,60,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Six
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (7,1,10,40,50,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Seven
   </A>
   <BR>
   <A
      HREF="javascript://"
      ONMOUSEOVER="music.playRandomNote (8,1,10,30,40,100,70,1000,1000,100,100,0,127)"
   >
      Just&nbsp;a&nbsp;Link&nbsp;-&nbsp;Eight
   </A>
   <BR>
   </FONT>
</TD></TR></TABLE>

</BODY></HTML>

In the source code lising above, the text that is highlighted represents the code that is necessary for achieving the randomized chime effect. Note how we have sourced in the JavaScript file "music-object-x-dynamic.js". Without this file sourced into the page, the playRandomNote method would not be defined and the code would produce JavaScript errors. Notice also how we have sourced in this extension file after first sourcing in the core "music-object.js" file. If you are unfamiliar with Music Object extensions, consult the section About Music Object Extensions.

In this example, we are assuming that the files "music-object.js", "music-object-x-dynamic.js", and "stub.rmf" are all located in the same folder as the HTML document that is to be sonified. If this is not the case in your own particular situation, then you should specify correct paths to the locations of these files relative to the location of the HTML page to be sonified.

All Together Now

By layering multiple notes together at randomly selected pitches, one can achieve some pretty cool and funky results. The possibilities are virtually limitless. For example, try out the various button click sounds below. Be sure to click each button several times to see how the sound texture is always changing, but still conforms to a certain unique identity that differentiates it from all the other button sounds. Even though there is a fair amount of randomization taking place, each button still retains its own quality. Click buttons now...

              

Now, let's take a look at the source code for this navigation bar...

<HTML><TITLE>Eerie Buttons</TITLE></HTML>
<BODY>

<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-dynamic.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

music = new Music ();
music.stubEmbed ('stub.rmf');

// --></SCRIPT>

<CENTER>
<FORM>
   <INPUT
      TYPE="button"
      VALUE="Button 1"
      ONCLICK="
         music.playRandomNote (1,1,82,84,105,30,20,1000,1000,100,100,0,127);
         music.playRandomNote (2,1,79,84,105,30,20,1000,1000,100,100,0,127);
         music.playRandomNote (3,0,128+71,85,102,40,40,200,200,100,100,0,127);
      "
   >
   &nbsp;&nbsp;
   <INPUT
      TYPE="button"
      VALUE="Button 2"
      ONCLICK="
         music.playRandomNote (1,1,128+82,67,97,30,20,100,100,100,100,0,127);
         music.playRandomNote (2,1,128+82,67,97,30,20,100,100,100,100,0,127);
         music.playRandomNote (3,1,38,26,43,50,50,500,500,100,100,0,127);
      "
   >
   &nbsp;&nbsp;
   <INPUT
      TYPE="button"
      VALUE="Button 3"
      ONCLICK="
         music.playRandomNote (1,0,128+56,84,84,50,30,3000,3000,100,100,0,127);
         music.playRandomNote (2,1,119,25,50,100,100,3000,3000,100,100,0,127);
         music.playRandomNote (3,1,93,50,76,50,50,300,300,100,100,0,127);
      "
   >
   &nbsp;&nbsp;
   <INPUT
      TYPE="button"
      VALUE="Button 4"
      ONCLICK="
         music.playRandomNote (1,0,128+56,2,20,50,30,3000,3000,100,100,0,127);
         music.playRandomNote (2,0,128+56,2,20,50,30,3000,3000,100,100,0,127);
         music.playRandomNote (3,0,128+56,2,20,50,30,3000,3000,100,100,0,127);
      "
   >
   &nbsp;&nbsp;
   <INPUT
      TYPE="button"
      VALUE="Button 5"
      ONCLICK="
         music.playRandomNote (1,1,33,41,54,100,100,2000,2000,100,100,64,64);
         music.playRandomNote (2,1,33,81,102,10,10,4000,4000,100,100,0,127);
         music.playRandomNote (3,1,33,81,102,10,10,4000,4000,100,100,0,127);
         music.playRandomNote (4,1,33,81,102,10,10,4000,4000,100,100,0,127);
         music.playRandomNote (5,1,33,81,102,10,10,4000,4000,100,100,0,127);
      "
   >
   &nbsp;&nbsp;
   <INPUT
      TYPE="button"
      VALUE="Button 6"
      ONCLICK="
         music.playRandomNote (1,1,50,54,80,100,100,500,500,60,60,64,64);
         music.playRandomNote (2,1,50,54,80,100,100,500,500,60,60,64,64);
         music.playRandomNote (3,1,50,54,80,100,100,500,500,60,60,64,64);
         music.playRandomNote (4,1,50,54,80,100,100,500,500,60,60,64,64);
      "
   >
</FORM>
</CENTER>
<P>

</BODY></HTML>

In the source code listing above, the text that is highlighted indicates the code that is necessary for achieving the various different "eerie" button sounds.